# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=mintty
pkgname=${_realname}-git
pkgver=2.1.5.0.859.f9db71f
pkgrel=1
pkgdesc="Terminal emulator with native Windows look and feel"
arch=('i686' 'x86_64')
license=('GPL3')
groups=('base')
conflicts=("${_realname}")
provides=("${_realname}")
makedepends=('git')
depends=('sh')
url="https://mintty.github.io"
source=("git+https://github.com/mintty/mintty")
sha256sums=('SKIP')

pkgver() {
  cd "$srcdir/${_realname}"
  local _major=$(cat src/appinfo.h | grep -F 'MAJOR_VERSION' | head -1 | sed -e 's/.* //')
  local _minor=$(cat src/appinfo.h | grep -F 'MINOR_VERSION' | head -1 | sed -e 's/.* //')
  local _patch=$(cat src/appinfo.h | grep -F 'PATCH_NUMBER'  | head -1 | sed -e 's/.* //')
  local _build=$(cat src/appinfo.h | grep -F 'BUILD_NUMBER'  | head -1 | sed -e 's/.* //')
  printf "%s.%s.%s.%s.%s.%s" "${_major}" "${_minor}" "${_patch}" "${_build}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  cd "${srcdir}/${_realname}"
  cd src
  make wm_names.t
  make vk_names.t
  cd ..
  make
}

package() {
  cd "${srcdir}/${_realname}"
  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/man/man1
  mkdir -p ${pkgdir}/usr/share/licenses/${_realname}


  install -m755 bin/mintty.exe ${pkgdir}/usr/bin/mintty.exe
  install -m644 docs/mintty.1 ${pkgdir}/usr/share/man/man1/mintty.1

  install -m644 LICENSE ${pkgdir}/usr/share/licenses/${_realname}/
  install -m644 LICENSE.Oxygen ${pkgdir}/usr/share/licenses/${_realname}/
  install -m644 LICENSE.PuTTY ${pkgdir}/usr/share/licenses/${_realname}/
}
